﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XiaoYuStockAnalysis.BusinessLogic.Business;
using XiaoYuStock.Core;
using XiaoYuStock.Model;
using XiaoYuStock.Model.Models;
using XiaoYuStock.AppService;

namespace XiaoYuStock.Hosts.Jobs
{
    public class AllSharesJob : IJob
    {
        /// <summary>
     /// 执行任务
     /// </summary>
     /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            LogHelper.Info("获取股票资料任务开始");

            try
            {
                ShareListDataBusiness shareBus = new ShareListDataBusiness();
                SharesService shareSrv = new SharesService();
                DataMapping dataMapping = new DataMapping();

                //var data = shareSrv.GetSHData();
                //if (data != null)
                //{
                //    data.ForEach(t=> shareBus.SynShare(dataMapping.ConvertShareList(t, SharesType.SH, "A")));
                //}
                //System.Threading.Thread.Sleep(8000);
                var data = shareSrv.GetSZDataA();
                if (data != null)
                {
                    data.ForEach(t => shareBus.SynShare(dataMapping.ConvertShareList(t, SharesType.SZ, "A")));
                }
                System.Threading.Thread.Sleep(8000);
                data = shareSrv.GetSZDataS();
                if (data != null)
                {
                   
                    data.ForEach(t => shareBus.SynShare(dataMapping.ConvertShareList(t, SharesType.SZ, "S")));
                }
                System.Threading.Thread.Sleep(8000);
                data = shareSrv.GetSZDataM();
                if (data != null)
                {
                    data.ForEach(t => shareBus.SynShare(dataMapping.ConvertShareList(t, SharesType.SZ, "M")));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取股票资料任务异常" + ex.ToString() + ex.StackTrace);
                if (ex.InnerException != null)
                {
                    LogHelper.Error("内部错误" + ex.InnerException.ToString());
                }
            }

            LogHelper.Info("获取股票资料任务完成");
        }
    }
}
